//
//  MJRefreshNormalHeader+Extension.m
//  CityFire
//
//  Created by liuyangzhu on 2017/10/5.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "MJRefreshNormalHeader+Extension.h"

@implementation MJRefreshNormalHeader (Extension)


+ (instancetype)headerForCustomWithRefreshingTarget:(id)target refreshingAction:(SEL)action
{
    
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的startInitRequest方法）
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:target refreshingAction:action];
    
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    header.autoChangeAlpha = YES;
    
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    
    // 背景色
    //    header.backgroundColor = MAIN_VIEW_BG_COLOR;
    
    // 设置文本
    [header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [header setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    [header setTitle:@"松开刷新" forState:MJRefreshStatePulling];
    [header setTitle:@"刷新完成" forState:MJRefreshStateNoMoreData];
    
    
    
    return header;
}

- (void)placeSubviews
{
    [super placeSubviews];
    
    
    
    // 箭头位置
    
    // 箭头
    CGFloat arrayWidthRate = 0.7; //宽度缩放率
    CGFloat arrayHeightRate = 0.7; //高度缩放率
    CGSize arraySize = self.arrowView.image.size;
    arraySize = CGSizeMake(arraySize.width * arrayWidthRate, arraySize.height * arrayHeightRate);
    self.arrowView.mj_size = arraySize;
    CGFloat arrowCenterX = self.mj_w * 0.59; // 原来是0.5.向右调整
    if (!self.stateLabel.hidden) {
        arrowCenterX -= 100;
    }
    CGFloat arrowCenterY = self.mj_h * 0.5;
    self.arrowView.center = CGPointMake(arrowCenterX, arrowCenterY);
    
    // 颜色浅一点
    self.arrowView.alpha = 0.3;
    self.stateLabel.textColor = [UIColor colorWithRed:203 / 255.0 green:203 / 255.0 blue:203 / 255.0 alpha:1.0];
//    RGBCOLOR(203, 203, 203);
    
    // 圈圈
    UIActivityIndicatorView *loadingView = [self performSelector:@selector(loadingView)];
    loadingView.frame = self.arrowView.frame;
    
    // 整体位移
    CGPoint center = self.center;
    center.x = [UIScreen mainScreen].bounds.size.width / 2 + 22;
    self.center = center;
}

@end
